package com.yh.spring.struts.controller;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.yh.spring.mybatis.model.User;
import com.yh.spring.mybatis.service.IUserService;

public class UserAction extends ActionSupport implements ModelDriven<Object> {
	private static final long serialVersionUID = 1L;

	@Autowired
	private IUserService userService;
	
	private User user;

	public User getUser() {
		return user;
	}

	public String findUser(){
	        user = userService.findUser(user);
	        if(user!=null){
	        	ServletActionContext.getRequest().getSession().setAttribute("userSession", user);
	            return "success";
	        }else{  
	            return "error";
	        }  

		/*HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();
		list=userService.findUser(user);
		request.setAttribute("user", list);
		 return "success";*/
	}
	
	public IUserService getUserService() {
		return userService;
	}

	public void setUserService(IUserService userService) {
		this.userService = userService;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Override
	public User getModel() {
		if (user == null) {
			user = new User();
		}
		return user;
	}

}
